package com.ruoyi.base.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.base.domain.BaseSemster;
import com.ruoyi.base.service.IBaseSemsterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学期Controller
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Api("学期信息管理")
@RestController
@RequestMapping("/base/semster")
public class BaseSemsterController extends BaseController
{
    @Autowired
    private IBaseSemsterService baseSemsterService;

    /**
     * 查询学期列表
     */
    @ApiOperation("获取学期列表")
    @PreAuthorize("@ss.hasPermi('base:semster:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSemster baseSemster)
    {
        startPage();
        List<BaseSemster> list = baseSemsterService.selectBaseSemsterList(baseSemster);
        return getDataTable(list);
    }
    

    /**
     * 查询学期列表
     */
    @ApiOperation("获取学期列表")
    @GetMapping("/select")
    public TableDataInfo select(BaseSemster baseSemster)
    {
        List<BaseSemster> list = baseSemsterService.selectBaseSemsterList(baseSemster);
        return getDataTable(list);
    }
    

    /**
     * 获取当前学期
     */
    @ApiOperation("获取当前学期")
    @GetMapping("/current")
    public AjaxResult current()
    {
    	return AjaxResult.success(baseSemsterService.getCurrentSemster()); 
    }

    /**
     * 导出学期列表
     */
    @ApiOperation("导出学期列表")
    @PreAuthorize("@ss.hasPermi('base:semster:export')")
    @Log(title = "学期", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseSemster baseSemster)
    {
        List<BaseSemster> list = baseSemsterService.selectBaseSemsterList(baseSemster);
        ExcelUtil<BaseSemster> util = new ExcelUtil<BaseSemster>(BaseSemster.class);
        return util.exportExcel(list, "semster");
    }

    /**
     * 获取学期详细信息
     */
    @ApiOperation("获取学期详细信息")
    @ApiImplicitParam(name = "id", value = "学期ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:semster:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseSemsterService.selectBaseSemsterById(id));
    }

    /**
     * 新增学期
     */
    @ApiOperation("新增学期")
    @PreAuthorize("@ss.hasPermi('base:semster:add')")
    @Log(title = "学期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSemster baseSemster)
    {
        return toAjax(baseSemsterService.insertBaseSemster(baseSemster));
    }

    /**
     * 修改学期
     */
    @ApiOperation("修改学期")
    @PreAuthorize("@ss.hasPermi('base:semster:edit')")
    @Log(title = "学期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSemster baseSemster)
    {
        return toAjax(baseSemsterService.updateBaseSemster(baseSemster));
    }

    /**
     * 删除学期
     */
    @ApiOperation("删除学期")
    @ApiImplicitParam(name = "id", value = "学期ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:semster:remove')")
    @Log(title = "学期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSemsterService.deleteBaseSemsterByIds(ids));
    }
}
